@extends('layout.admin')
@section('content')
    <style>
        .layui-btn {
            height: 25px;
            line-height: 25px;
        }
    </style>
    <div style="">
        <div style="padding: 5px 15px 5px 15px;border:1px solid #e8e8e8;background: white;border: 1px solid #e6e6e6">
           <span class="layui-breadcrumb" style="visibility:visible">
              <a href="{{url('/')}}"><i class="layui-icon" style="font-size: 14px"></i> 首页  </a>
              <a href="{{url('/admin')}}"><cite> 文章管理 </cite></a>
            </span>
        </div>
        <div style="padding: 5px 15px 0 15px">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>用户管理</legend>
            </fieldset>
            <div class="layui-tab layui-tab-card">
                <ul class="layui-tab-title">
                    <li class=""><a href="{{url('/admin')}}">用户列表</a></li>
                    <li class=""><a href="{{url('/admin/create')}}">用户添加</a></li>
                    <li class="layui-this"><a href="{{url('/admin/create')}}">用户修改</a></li>
                </ul>
                <div class="layui-tab-content" style="height: 100%;">
                    <blockquote class="layui-elem-quote layui-text">
                        表单数据
                    </blockquote>
                    <form action="{{url('/admin/').'/' .$field->id}}" class="layui-form" method="post">
                        {{ method_field('PUT') }}
                        {{csrf_field()}}
                        <div style="border: 1px solid #c2c2c2;">
                            <div class="layui-bg-white">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">昵称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="name" lay-verify="required" required autocomplete="off" value="{{$field->name}}" placeholder="昵称" class="layui-input layui-form-danger">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-bg-white">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">手机号</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="mobile" lay-verify="required" autocomplete="off" value="{{$field->mobile}}" placeholder="手机号" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-bg-white">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">邮箱</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="email" autocomplete="off" value="{{$field->email}}" placeholder="邮箱" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-bg-white">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">头像</label>
                                    <button type="button" class="layui-btn" id="test1">上传头像</button>
                                    <input type="hidden" name="avatar" id="avatar" value="{{$field->avatar}}">
                                    <div class="layui-upload-list">
                                        <img class="layui-upload-img" id="demo1" src="{{env('WEBSITE_URL') .'/storage/' .$field->avatar}}">
                                        <p id="demoText"></p>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-bg-white">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">状态</label>
                                    @if($field->status == 1)
                                        <div class="layui-input-block">
                                            <input type="radio" name="status" value="1" title="显示" checked>
                                            <input type="radio" name="status" value="0" title="隐藏">
                                        </div>
                                    @else
                                        <div class="layui-input-block">
                                            <input type="radio" name="status" value="1" title="显示">
                                            <input type="radio" name="status" value="0" title="隐藏" checked>
                                        </div>
                                    @endif
                                </div>
                            </div>
                            <div class="layui-bg-white">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">密码</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="password" autocomplete="off" placeholder="新密码,如果不填写则还是原密码" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-bg-white">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">确认密码</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="password_confirmation" autocomplete="off" placeholder="确认新密码,如果不填写则还是原密码" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-bg-white submit">
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <style>
        .layui-bg-white {
            padding: 20px 50px 5px 50px;
            border-top: 1px dashed #c2c2c2;
            background: white;
        }

        .layui-bg-white:nth-of-type(1) {
            border-top: none;
        }

        .layui-upload-img {
            width: 92px;
            height: 92px;
            margin: 0 10px 10px 0;
        }

        #demoText {
            display: inline-block;
        }

        .submit {
            padding-bottom: 5px;
        }
    </style>

    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;
            // layer.alert("")
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: '/uploader/'
                , data: {'_token': "{{csrf_token()}}"}
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.success == false) {
                        return layer.msg('上传失败');
                    }
                    $('#avatar').val(res.data.message);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });

        });
        layui.use('form', function () {
            var form = layui.form;
            //监听提交
            form.on('submit(formDemo)', function (data) {
                layer.msg(JSON.stringify(data.field));
                return false;
            });
        });
    </script>
@endsection